package com.jiyun.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.domain.PlayersApplication;
import com.domain.User;
import com.jiyun.admin.mapper.PlayersApplicationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.admin.mapper.UserMapper;
import com.jiyun.admin.service.PlayersApplicationService;
import com.spyx.common.result.Result;
import org.springframework.stereotype.Service;

@Service
public class PlayersApplicationServiceImpl extends ServiceImpl<PlayersApplicationMapper, PlayersApplication> implements PlayersApplicationService {

    private final PlayersApplicationMapper playersApplicationMapper;

    private final UserMapper userMapper;

    public PlayersApplicationServiceImpl(PlayersApplicationMapper playersApplicationMapper,UserMapper userMapper){
        this.playersApplicationMapper = playersApplicationMapper;
        this.userMapper = userMapper;
    }



    @Override
    public Result updatelay(PlayersApplication playersApplication) {

        int i = playersApplicationMapper.updateById(playersApplication);
        if (i==1&&playersApplication.getStatus()==1){
            PlayersApplication userId = playersApplicationMapper.selectOne(new QueryWrapper<PlayersApplication>().eq("user_id", playersApplication.getUserId()));
            User user = userMapper.selectById(userId.getUserId());
            user.setPid(userId.getId());
            userMapper.updateById(user);
        }
        return Result.ok();
    }
}
